package com.buss.product.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.buss.core.dic.RecordStatus;

@Entity
@Table(name="base_cateprop")
@TableGenerator(name="cateprop_pk_sequence",initialValue=1,allocationSize=1,pkColumnName="seq_col",
		pkColumnValue="cateprop_seq",valueColumnName="seq_val",table="product_pk_sequence")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JsonIgnoreProperties(value={"propGroup"})
public class CateProp implements Serializable {

	private static final long serialVersionUID = 6387097002599776584L;

	/**属性Id*/
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="cateprop_pk_sequence")
	private Long id;
	
	/**属性编码*/
	@Column(nullable=false,length=20)
	private String code;
	
	/**属性名称*/
	@Column(nullable=false,length=100)
	private String name;
	
	/**分组信息*/
	@ManyToOne(cascade = CascadeType.REFRESH,fetch = FetchType.LAZY,optional = true)
	@JoinColumn(name="groupId",nullable=false)
	private CatePropGroup propGroup;
	
	/**属性选择类型 uniqueprop:唯一属性，singlechoice:单选属性，multichoice:多选属性。默认为:uniqueprop*/
	@Column(length=20)
	@Enumerated(value=EnumType.STRING)
	private PropSelectType selectType;
	
	/**展现时样式 行：col,行：line,组合：composite,默认为composite,主要用于统计时按照交叉表进行展现，只能有一个为列和一个为行，如果不设置将会按照一个交集一行进行显示*/
	@Column(length=20)
	@Enumerated(value=EnumType.STRING)
	private PropColOrLine colOrLine;
	
	/**
	 * 属性值录入方式 选择用户录入属性值时的方式，manualWay:手工录入。
	 * dicChoice:从数据字典选择，如果选择从数据字典选择，在此会要求对应数据字典中的类型。
	 * 从列表中选择:listChoice，该选择列表需要再此维护进去。
	 * dicChoice即可以针对唯一属性也可以针对单选活多选属性
	 */
	@Column(length=20)
	@Enumerated(value=EnumType.STRING)
	private PropEntryWay entryWay; 
	
	/**对应数据字典中的分类编码*/
	@Column(length = 20)
	private String dicCode;
	
	@Transient
	private String dicName;
	
	/**列表选择时的属性值：出入方式为:value1 \n value2 \n value3，属性值中不能包括~字符*/
	@Column(length=4000)
	private String listValues;
	
	@Transient
	private String[] listValuesArr;
	/**
	 * 设置该属性在商品列表中是否显示，如果是多选属性，那么显示时将相互去交集，如：索爱x10i手机，包括（颜色：黑色，白色。套餐：套餐一，套餐二），那么列表商品列表将显示为：
	 *	索爱x10i      黑色   套餐一     m     10
	 *	索爱x10i      黑色   套餐二     n		100
	 *	索爱x10i      黑色   套餐一     m     10			
	 *	索爱x10i      白色   套餐一     m     100
	 *	索爱x10i      白色   套餐二     n		200
	 */
	private Boolean listVisible;
	
	/**在统计商品明细时，是否显示该属性，类似商品列表是否显示*/
	private Boolean statisVisible;
	
	/**能否进行检索*/
	private Boolean isSearch;
	
	/**排序序号*/
	private Long sortOrder;
	
	/**状态*/
	@Column(length=20)
	@Enumerated(value=EnumType.STRING)
	private RecordStatus status;
	
	
	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public String getCode() {
		return code;
	}


	public void setCode(String code) {
		this.code = code;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}
	
	public CatePropGroup getPropGroup() {
		return propGroup;
	}


	public void setPropGroup(CatePropGroup propGroup) {
		this.propGroup = propGroup;
	}


	public PropSelectType getSelectType() {
		return selectType;
	}


	public void setSelectType(PropSelectType selectType) {
		this.selectType = selectType;
	}


	public PropColOrLine getColOrLine() {
		return colOrLine;
	}


	public void setColOrLine(PropColOrLine colOrLine) {
		this.colOrLine = colOrLine;
	}


	public PropEntryWay getEntryWay() {
		return entryWay;
	}


	public void setEntryWay(PropEntryWay entryWay) {
		this.entryWay = entryWay;
	}


	public String getDicCode() {
		return dicCode;
	}


	public void setDicCode(String dicCode) {
		this.dicCode = dicCode;
	}


	public String getDicName() {
		return dicName;
	}


	public void setDicName(String dicName) {
		this.dicName = dicName;
	}


	public String getListValues() {
		return listValues;
	}


	public void setListValues(String listValues) {		
		this.listValues = listValues;
	}


	public String[] getListValuesArr() {
		listValuesArr = this.listValues.split("\n");
		return listValuesArr;
	}


	public void setListValuesArr(String[] listValuesArr) {
		this.listValuesArr = listValuesArr;
	}


	public Boolean getListVisible() {
		return listVisible;
	}


	public void setListVisible(Boolean listVisible) {
		this.listVisible = listVisible;
	}


	public Boolean getStatisVisible() {
		return statisVisible;
	}


	public void setStatisVisible(Boolean statisVisible) {
		this.statisVisible = statisVisible;
	}


	public Boolean getIsSearch() {
		return isSearch;
	}


	public void setIsSearch(Boolean isSearch) {
		this.isSearch = isSearch;
	}


	public Long getSortOrder() {
		return sortOrder;
	}


	public void setSortOrder(Long sortOrder) {
		this.sortOrder = sortOrder;
	}


	public RecordStatus getStatus() {
		return status;
	}


	public void setStatus(RecordStatus status) {
		this.status = status;
	}


	public enum PropSelectType {

		uniqueProp("唯一属性"),
		singleChoice("单选属性"),
		multichoice("多选属性");
		
		private String value;
		
		PropSelectType(String value){
			this.value = value;
		}
		
		public String getValue(){
			return value;
		}
	}
	
	public enum PropColOrLine {

		col("列样式"),
		line("行样式"),
		composite("组合样式");
		
		private String value;
		PropColOrLine(String value){
			this.value = value;
		}
		
		public String getValue(){
			return value;
		}
	}


	public enum PropEntryWay{
		manualWay("手工录入"),
		listChoice("列表选择"),
		dicChoice("数据字典选择");
		
		private String value;
		
		PropEntryWay(String value){
			this.value = value;
		}
		public String getValue(){
			return value;
		}
	}
	
}
